package org.jeecg.modules.bugdone.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.bugdone.entity.BugdoneDetail;
import org.jeecg.modules.bugdone.service.IBugdoneDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;

 /**
 * @Description: bugdone详细信息
 * @Author: jeecg-boot
 * @Date:   2023-09-04
 * @Version: V1.0
 */
@Api(tags="bugdone详细信息")
@RestController
@RequestMapping("/bugdone/bugdoneDetail")
@Slf4j
public class BugdoneDetailController extends JeecgController<BugdoneDetail, IBugdoneDetailService> {
	@Autowired
	private IBugdoneDetailService bugdoneDetailService;
	
	/**
	 * 分页列表查询
	 *
	 * @param bugdoneDetail
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	@AutoLog(value = "bugdone详细信息-分页列表查询")
	@ApiOperation(value="bugdone详细信息-分页列表查询", notes="bugdone详细信息-分页列表查询")
	@GetMapping(value = "/list")
	public Result<?> queryPageList(BugdoneDetail bugdoneDetail,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<BugdoneDetail> queryWrapper = QueryGenerator.initQueryWrapper(bugdoneDetail, req.getParameterMap());
		Page<BugdoneDetail> page = new Page<BugdoneDetail>(pageNo, pageSize);
		IPage<BugdoneDetail> pageList = bugdoneDetailService.page(page, queryWrapper);
		return Result.OK(pageList);
	}
	
	/**
	 *   添加
	 *
	 * @param bugdoneDetail
	 * @return
	 */
	@AutoLog(value = "bugdone详细信息-添加")
	@ApiOperation(value="bugdone详细信息-添加", notes="bugdone详细信息-添加")
	@PostMapping(value = "/add")
	public Result<?> add(@RequestBody BugdoneDetail bugdoneDetail, @RequestParam(name = "bugdoneId") String bugdoneId) {
		bugdoneDetail.setBugdoneId(bugdoneId);
//		bugdoneDetail.setSolver(bugdoneDetail.getAssign());
		bugdoneDetailService.save(bugdoneDetail);
		return Result.OK("添加成功！");
	}
	
	/**
	 *  编辑
	 *
	 * @param bugdoneDetail
	 * @return
	 */
	@AutoLog(value = "bugdone详细信息-编辑")
	@ApiOperation(value="bugdone详细信息-编辑", notes="bugdone详细信息-编辑")
	@PutMapping(value = "/edit")
	public Result<?> edit(@RequestBody BugdoneDetail bugdoneDetail) {
		bugdoneDetailService.updateById(bugdoneDetail);
		return Result.OK("编辑成功!");
	}
	
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "bugdone详细信息-通过id删除")
	@ApiOperation(value="bugdone详细信息-通过id删除", notes="bugdone详细信息-通过id删除")
	@DeleteMapping(value = "/delete")
	public Result<?> delete(@RequestParam(name="id",required=true) String id) {
		bugdoneDetailService.removeById(id);
		return Result.OK("删除成功!");
	}
	
	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "bugdone详细信息-批量删除")
	@ApiOperation(value="bugdone详细信息-批量删除", notes="bugdone详细信息-批量删除")
	@DeleteMapping(value = "/deleteBatch")
	public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.bugdoneDetailService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}


	 @AutoLog(value = "bugdone详细信息-批量修改")
	 @ApiOperation(value="bugdone详细信息-批量修改", notes="bugdone详细信息-批量修改")
	 @PutMapping(value = "/editBatch")
	 public Result<?> editBatch(@RequestBody()String ids,  String num,String solver) {
		 UpdateWrapper<BugdoneDetail> bugdoneDetailUpdateWrapper = new UpdateWrapper<>();
		 if ("2".equals(num)){
			 bugdoneDetailUpdateWrapper.in("id", ids);
			 bugdoneDetailUpdateWrapper.set("state", num);
			 bugdoneDetailUpdateWrapper.set("solver", solver);
			 bugdoneDetailService.update(bugdoneDetailUpdateWrapper);
		}
		 if ("3".equals(num)){
			 System.out.println("1111111111111111111111111111");
		 }
		 return Result.OK("批量修改成功!");
	 }
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "bugdone详细信息-通过id查询")
	@ApiOperation(value="bugdone详细信息-通过id查询", notes="bugdone详细信息-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
		BugdoneDetail bugdoneDetail = bugdoneDetailService.getById(id);
		if(bugdoneDetail==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(bugdoneDetail);
	}

    /**
    * 导出excel
    *
    * @param request
    * @param bugdoneDetail
    */
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, BugdoneDetail bugdoneDetail) {
        return super.exportXls(request, bugdoneDetail, BugdoneDetail.class, "bugdone详细信息");
    }

    /**
      * 通过excel导入数据
    *
    * @param request
    * @param response
    * @return
    */
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, BugdoneDetail.class);
    }

}
